port := 5001
image := bluetooth-api
tag := dev

# 其它依赖环境的端口
BLURTOOTH_MYSQL_PORT := 5002
BLURTOOTH_REDIS_PORT := 5003
BLURTOOTH_MONGODB_PORT := 5004

container := api  # 查看容器的日志

docker_exec = docker exec -it bluetooth_api_1



docker-image: Dockerfile
	docker build -t ${image}:${tag} .

python: docker-image
	docker run -it --name buletooth-pro --rm -v ${PWD}:/opt/bluetooth/ -d bluetooth-api:dev bash

dbinit: docker-image
	${docker_exec} python manager.py db init

migrate: docker-image
	${docker_exec} python manager.py db migrate

upgrade: docker-image
	${docker_exec} python manager.py db upgrade

run: docker-image docker-compose.yml
	API_PORT=${port} BLURTOOTH_MYSQL_PORT=${BLURTOOTH_MYSQL_PORT} BLURTOOTH_REDIS_PORT=${BLURTOOTH_REDIS_PORT} BLURTOOTH_MONGODB_PORT=${BLURTOOTH_MONGODB_PORT} docker-compose up -d

stop: docker-compose.yml
	API_PORT=${port} BLURTOOTH_MYSQL_PORT=${BLURTOOTH_MYSQL_PORT} BLURTOOTH_REDIS_PORT=${BLURTOOTH_REDIS_PORT} BLURTOOTH_MONGODB_PORT=${BLURTOOTH_MONGODB_PORT} docker-compose stop

down: docker-compose.yml
	API_PORT=${port} BLURTOOTH_MYSQL_PORT=${BLURTOOTH_MYSQL_PORT} BLURTOOTH_REDIS_PORT=${BLURTOOTH_REDIS_PORT} BLURTOOTH_MONGODB_PORT=${BLURTOOTH_MONGODB_PORT} docker-compose down

logs:
	docker logs -f bluetooth_${container}_1
